<template>
	<div class="">
		<div class="crumbs">
			<h2 class="">机构反馈管理</h2>
		</div>
		<div class="container ">
			<div class="handle-box margin-bottom20 row-me row-center">
				<el-form :model="query" label-width="80px" class="ipt row-me">
					<el-form-item label="模糊搜索">
						<el-input v-model="query.key" placeholder="请输入姓名、手机号"></el-input>
					</el-form-item>
					<!-- <el-form-item label="地区">
						<el-cascader v-model="query.area" :options="areaList" :props="{ expandTrigger: 'hover' }"
							@change="handleChange"></el-cascader>
					</el-form-item> -->
				</el-form>

				<div class="margin-bottom20 margin-left20">
					<el-button type="primary" @click="handleSearch">查询</el-button>
					<el-button @click="resetClick">重置</el-button>
					<el-button type="primary" class="handle-del" @click="exportClick">批量导出</el-button>
					<el-button type="primary" class="handle-del" @click="feedbackType">反馈类型</el-button>
				</div>
			</div>
			<el-table :data="tableData" border class="table" ref="multipleTable" header-cell-class-name="table-header"
				@selection-change="handleSelectionChange">
				<el-table-column type="selection" width="40" align="center"></el-table-column>
				<!-- <el-table-column type="index" width="55" align="center" label="序号"></el-table-column> -->
				<el-table-column prop="userName" label="反馈用户" align="center"></el-table-column>
				<el-table-column prop="phone" label="手机号" align="center">
					<!-- <template slot-scope="scope">
						<span>封面图</span>
						<span>名称</span>
					</template> -->
				</el-table-column>
				<el-table-column prop="organName" label="机构名称" align="center" show-overflow-tooltip></el-table-column>
				<el-table-column prop="typeName" label="反馈类型" align="center"></el-table-column>
				<el-table-column prop="content" label="反馈内容" align="center" show-overflow-tooltip></el-table-column>
				<el-table-column prop="createTime" label="反馈时间" align="center"></el-table-column>

			</el-table>
			<div class="pagination">
				<el-pagination background layout="total, prev, pager, next" :current-page="query.pageNumber"
					:page-size="query.pageSize" :total="pageTotal" @current-change="handlePageChange"></el-pagination>
			</div>
		</div>

		<!-- 反馈类型 -->
		<el-dialog title="反馈类型" :visible.sync="feedbackShow" v-if="feedbackShow" width="40%">
			<el-table :data="feedbackList" border>
				<el-table-column label="名称" align="center">
					<template slot-scope="{row}">
						<el-input v-model="row.name" v-if="row.isEdit"></el-input>
						<span v-else>{{row.name}}</span>
					</template>
				</el-table-column>
				<el-table-column label="操作" align="center" width="200">
					<template slot-scope="scope">
						<el-button type="text" v-if="scope.row.isEdit" @click="handleTagAdd(scope.row)">保存</el-button>
						<el-button type="text" @click="scope.row.isEdit=true" v-else>编辑</el-button>
						<el-popconfirm title="确认删除？" @confirm="handleTagDel(scope.row.id)">
							<el-button slot="reference" type="text">删除</el-button>
						</el-popconfirm>
					</template>
				</el-table-column>
			</el-table>
			<div class="margin-top10">
				<el-pagination background layout="->,total,sizes, prev, pager, next" :current-page="tagQuery.pageNumber"
					:page-sizes="[10, 20, 30, 40]" @size-change="handleSizeTagChange" :page-size="tagQuery.pageSize"
					:total="pageTagTotal" @current-change="handlePageTagChange"></el-pagination>
			</div>
			<div class="margin-top20 row-me center-all">
				<el-input v-model="tagQuery.name" placeholder="请输入名称" class="margin-right20 width300"></el-input>
				<el-button type="primary" @click="handleTagAdd">新增</el-button>
			</div>
			<span slot="footer">
				<el-button type="primary" @click="feedbackShow = false">关 闭</el-button>
			</span>
		</el-dialog>

	</div>
</template>

<script>
	export default {
		name: 'categoryTable',
		data() {
			return {
				query: {
					name: '',
					type: '',
					pageNumber: 1,
					pageSize: 30
				},
				dialogTitle: '',
				tableData: [],
				multipleSelection: [],
				editVisible: false,
				pageTotal: 0,
				form: {},
				areaList: [{
					value: 'zhinan',
					label: '指南',
					children: [{
						value: 'shejiyuanze',
						label: '设计原则',
						children: [{
							value: 'yizhi',
							label: '一致'
						}, {
							value: 'fankui',
							label: '反馈'
						}, {
							value: 'xiaolv',
							label: '效率'
						}, {
							value: 'kekong',
							label: '可控'
						}]
					}, {
						value: 'daohang',
						label: '导航',
						children: [{
							value: 'cexiangdaohang',
							label: '侧向导航'
						}, {
							value: 'dingbudaohang',
							label: '顶部导航'
						}]
					}]
				}], //地区
				approveList: [],
				feedbackShow: false,
				feedbackList: [],
				tagQuery: {
					pageNumber: 1,
					pageSize: 10
				},
				pageTagTotal: 0,

			};
		},
		created() {
			this.getData();
		},
		methods: {
			// 反馈类型
			async getTagData() {
				const res = await this.$post('/admin/feeds/labelTypeAll', this.tagQuery)
				if (res.code == 1000) {
					this.feedbackList = res.data.list
					this.pageTagTotal = res.data.totalRow
					for (let item of this.feedbackList) {
						this.$set(item, 'isEdit', false)
					}
				}
			},
			// 标签分类分页
			handlePageTagChange(val) {
				this.tagQuery.pageNumber = val
				this.getTagData();
			},
			handleSizeTagChange(val) {
				this.tagQuery.pageSize = val
				this.getTagData();
			},
			// 新增编辑反馈类型
			handleTagAdd(row) {
				if (row.id) {
					this.$post('/admin/feeds/labelTypeUpdate', {
						id: row.id,
						name: row.name
					}).then(res => {
						if (res.code == 1000) {
							this.$message.success('编辑成功')
							this.getTagData()
							row.isEdit = false
						}
					})
				} else {
					this.$post('/admin/feeds/labelTypeSave', {
						name: this.tagQuery.name
					}).then(res => {
						if (res.code == 1000) {
							this.$message.success('新增成功')
							this.getTagData()
							this.tagQuery.name = ''
						}
					})
				}
			},
			//删除标签分类
			async handleTagDel(id) {
				const res = await this.$postForm('/admin/feeds/labelTypeDelete', {
					id
				})
				if (res.code == 1000) {
					this.$message.success('删除成功')
					this.getTagData()
				}
			},
			// 点击反馈类型
			feedbackType() {
				this.tagQuery = {
					pageNumber: 1,
					pageSize: 10
				}
				this.getTagData();
				this.feedbackShow = true;
			},
			parseParams(data) {
				try {
					var tempArr = [];
					for (var i in data) {
						var key = encodeURIComponent(i);
						var value = encodeURIComponent(data[i]);
						tempArr.push(key + '=' + value);
					}
					var urlParamsStr = tempArr.join('&');
					return urlParamsStr;
				} catch (err) {
					return '';
				}
			},
			// 批量导出
			exportClick() {
				if (this.multipleSelection.length == 0) {
					this.$message.warning('请先选择数据!')
					return
				}

				var list = [];
				this.multipleSelection.forEach((item, index) => {
					list.push(item.id)
				});

				let params = {};
				// params.pageSize = 1000000000;
				// let appid = localStorage.getItem('htk_appid');
				params.token = localStorage.getItem('token');
				params.ids = list;
				window.open(this.$host + '/admin/feeds/pageExport?' + this.parseParams(params));
			},
			// 选择省区
			handleChange(value) {
				console.log(value);
			},
			// 获取 easy-mock 的模拟数据
			getData() {
				this.$postForm('/admin/feeds/feedAll', this.query).then((res) => {
					if (res.code == 1000) {
						this.$forceUpdate(); //强制刷新
						this.tableData = res.data.list
						this.pageTotal = res.data.totalRow
					}
				}).catch((error) => {
					console.log(error)
				})

			},
			// 触发搜索按钮
			handleSearch() {
				this.$set(this.query, 'pageNumber', 1);
				this.getData();
			},
			// 点击重置
			resetClick() {
				this.query = {};
				this.$set(this.query, 'pageNumber', 1);
				this.getData();
			},
			// 多选操作
			handleSelectionChange(val) {
				this.multipleSelection = val;
			},
			// 编辑操作
			handleEdit(index, row) {
				this.title = '编辑排名';
				this.idx = index;
				this.form = row;
				this.rankingShow = true;
			},

			// 分页导航
			handlePageChange(val) {
				this.$set(this.query, 'pageNumber', val);
				this.getData();
			}
		}
	};
</script>

<style>
</style>